Components Interaction
Components in Porto like in many other architectures can interact with each other. However, we should be mindful of the dependencies across containers and especially across sections, if you intend to split into micro-services with ease.
Components Interaction Diagram
Request Life Cycle
The Request Life Cycle is the process through which an API call navigates through the main components of a Porto application. The following steps describe a basic API call scenario:
- The User calls an
Endpoint
in aRoute
file. Endpoint
calls aMiddleware
to handle the Authentication.Endpoint
calls its correspondingController
function.- The
Request
object, which is automatically injected in theController
, applies the request validation and authorization rules. Controller
calls anAction
and passes the data from theRequest
object to it.Action
executes the business logic, by calling multipleTasks
.Tasks
execute reusable subsets of the business logic, with eachTask
responsible for a single portion of the mainAction
.Action
prepares the final result to be returned to theController
, and may collect data from theTasks
if needed.Controller
builds the response using aView
orTransformer
, and sends it back to the User.
Views: should be used in case the App serves HTML pages.
Transformers: should be used in case the App serves JSON or XML data.
It is important to note that the Request
object handles request validation (and optionally, authorization rules, unless they are handled by middlewares.), while the Action
executes the business logic by calling Tasts
. The Tasks
are used to execute reusable subsets of the business logic, with each Task
responsible for a single portion of the main Action
. The View
or Transformer
is used to build the response that is sent back to the User.
Everything triggered before the controller pertains to the interface with the external system, such as the web or potentially blockchain in the future. Meanwhile, everything after the controller relates to your business logic, which remains reusable regardless of the external system.